package net.qiqbframework.event.dao.mfimpl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import net.qiqbframework.common.dto.PageResultDto;
import net.qiqbframework.common.utils.StringUtils;
import net.qiqbframework.eventsourcing.dao.DomainEventFeedbackDao;
import net.qiqbframework.eventsourcing.dao.DomainEventFeedbackPageCondition;
import net.qiqbframework.eventsourcing.dao.DomainEventFeedbackPo;
import net.qiqbframework.mf.BasicEntityPoDaoMfImpl;
import net.qiqbframework.mf.MpUtil;

import java.util.List;

public class DomainEventFeedbackDaoMfImpl extends BasicEntityPoDaoMfImpl<DomainEventFeedbackMapper, DomainEventFeedbackPo> implements DomainEventFeedbackDao {


    @Override
    public PageResultDto<DomainEventFeedbackPo> list4Page(DomainEventFeedbackPageCondition condition) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper
                .eq(DomainEventFeedbackPo::getEventId, condition.getEventId())
                .eq(DomainEventFeedbackPo::getStatus, condition.getStatus(), condition.getStatus() != null)
                .like(DomainEventFeedbackPo::getProcessListenerId, condition.getProcessListenerId(), StringUtils.nonEmptyOrNull(condition.getProcessListenerId()))
                .like(DomainEventFeedbackPo::getProcessResultMsg, condition.getProcessResultMsg(), StringUtils.nonEmptyOrNull(condition.getProcessResultMsg()))
                .like(DomainEventFeedbackPo::getApplicationName, condition.getApplicationName(), StringUtils.nonEmptyOrNull(condition.getApplicationName()))
                .like(DomainEventFeedbackPo::getInstanceName, condition.getInstanceName(), StringUtils.nonEmptyOrNull(condition.getInstanceName()))

        ;
        final Page<DomainEventFeedbackPo> page = super.page(MpUtil.ofPage(condition), queryWrapper);
        return MpUtil.toResult(page);
    }

    @Override
    public List<DomainEventFeedbackPo> listByEventId(String eventId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(DomainEventFeedbackPo::getEventId, eventId)

        ;
        return super.list(queryWrapper);
    }

}
